//---------------------------------------------------------------------------
#pragma hdrstop
#include "Article.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
Article::Article()
{
	initialize(0, "noname", 0, "unknown", 0.0, 0.0);
}
//---------------------------------------------------------------------------
Article::Article(int id, AnsiString name, int nrOfItems, AnsiString kind, double price, double deposit)
{
	initialize(id, name, nrOfItems, kind, price, deposit);
}
//---------------------------------------------------------------------------
void Article::initialize(int id, AnsiString name, int nrOfItems, AnsiString kind, double price, double deposit)
{
	this->articleID = id;
	this->name = name;
	this->nrOfItems = nrOfItems;
	this->kind = kind;
	this->price = price;
	this->deposit = deposit;
}
//---------------------------------------------------------------------------
int Article::getArticleID()	  { return this->articleID; }
//---------------------------------------------------------------------------
AnsiString Article::getName() { return this->name; }
//---------------------------------------------------------------------------
int Article::getNrOfItems()   { return this->nrOfItems; }
//---------------------------------------------------------------------------
AnsiString Article::getKind() { return this->kind; }
//---------------------------------------------------------------------------
double Article::getPrice()    { return this->price; }
//---------------------------------------------------------------------------
double Article::getDeposit()    { return this->deposit; }
//---------------------------------------------------------------------------
AnsiString Article::asAString()
{
	AnsiString temp = padRight(this->name, 18);
	// check the stock of the article
	if (this->nrOfItems > 0)
	{
		temp += padRight((AnsiString)this->nrOfItems, 5)+padRight(this->kind, 10)
				+padRight(AnsiString().FormatFloat("0.00", this->price), 7);
		// check the desposit of the article
		if (this->deposit > 0) {
			temp += AnsiString().FormatFloat("0.00", this->deposit);
		}
	}
	else
	{
    	temp += "- OUT OF STOCK";
	}
	return temp;
}
//---------------------------------------------------------------------------
void Article::decreaseNrOfItemsBy(int amount)
{
	this->nrOfItems -= amount;
}
//---------------------------------------------------------------------------
void Article::increaseNrOfItemsBy(int amount)
{
	this->nrOfItems += amount;
}
//---------------------------------------------------------------------------
AnsiString Article::padRight(AnsiString str, int len)
{
	if (str.Length() < len)
	{
		return str+AnsiString().StringOfChar(' ', len-str.Length());
	}
	else
	{
		return str+" ";
	}
}
//---------------------------------------------------------------------------
